package com.group3.service;

import com.group3.Feign.LiveRoomServiceFeign;
import com.group3.model.LiveRoom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

@Service
public class LiveRecommendationService {
    @Autowired
    private LiveRoomServiceFeign liveRoomServiceFeign;

    // 模拟用户兴趣数据（后续替换为ls-behavior模块的真实数据：用户喜欢的主播ID列表）
    private final List<Integer> mockInterestAnchorIds = List.of(1, 12, 13);
    private final Random random = new Random();

    public List<LiveRoom> getPersonalizedRecommendations(Integer uid) {
        // TODO: 调用ls-behavior模块获取用户行为历史和实时互动数据（用户兴趣、观看历史等）
        List<Integer> candidateAnchorIds = getCandidateAnchorIds(uid);
        return fetchLiveRoomsByAnchorIds(candidateAnchorIds);
    }

    private List<Integer> getCandidateAnchorIds(Integer uid) {
        // 模拟根据用户兴趣筛选候选主播ID
        List<Integer> candidates = new ArrayList<>();
        for (int i = 0; i < 3; i++) {
            candidates.add(mockInterestAnchorIds.get(random.nextInt(mockInterestAnchorIds.size())));
        }
        return candidates;
    }

    private List<LiveRoom> fetchLiveRoomsByAnchorIds(List<Integer> anchorIds) {
        // 模拟调用直播间服务获取对应主播的直播间（后续替换为Feign调用）
        return liveRoomServiceFeign.getLiveRoomsByAnchorIds(anchorIds).getData();
    }
}

